#!/bin/bash

extIn="JPG"
extOut="JPG"
outDir="to_web"

function conv {
	echo "I'm in directory \"$1\""
	dirs=`ls -ld -C1 */`
	for dir in ${dirs} 
	do	
		cd "${dir}"
		conv "${dir}"
		cd ..
	done

	mkdir ${outDir}

	files=`ls -C1 *.${extIn}`
	for file in $files
	do
		fileName=${file%.${extIn}}
#		ffmpeg -i ${fileName}.${extIn} ./out/${fileName}.${extOut}
		convert "${fileName}.${extIn}" -resize 600x600 "./${outDir}/${fileName}_conv.${extOut}"
		echo "create ./${outDir}/${fileName}_conv.${extOut}"
	done
}

IFS=$'\n'

conv "`pwd`"

echo "DONE !"
